package fexception;

import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Locale;
import java.util.ResourceBundle;

/**
 *
 */
public class MyMessageHandler {
	private static final Locale locale = Locale.getDefault();
	private static final ResourceBundle bundle = ResourceBundle.getBundle("MyMessages", locale);
	private static final NumberFormat numberFormat = NumberFormat.getNumberInstance(locale);
	private static final DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.DEFAULT, locale);

	public static NumberFormat getNumberFormat(){
		return numberFormat;
	}
	
	public static DateFormat getDateFormat(){
		return dateFormat;
	}
	
	public static String getString(String key){
		return bundle.getString(key);
	}
	
	public static String[] getStringArray(String key){
		return bundle.getStringArray(key);
	}
	
	public static String getString(String key, String [] args){
		String msg = bundle.getString(key);
		
		for(int i=0; i < args.length; i++) {
			msg = msg.replaceAll("\\{"+ i +"\\}", args[i] +"");
		}
		
		return msg;
	}
}
